﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Configuration;
using System.Collections;
using SharpMap.Converters.WellKnownText;

using SharpMap.CoordinateSystems;
using SharpMap.CoordinateSystems.Transformations;
namespace UTM
{
    public struct UTMPoint
    {
        public double x;
        public double y;
    }
    public struct GeoPoint
    {
        public double x;
        public double y;
    }
   public  class Cover
    {
       /// <summary>
       /// 将经纬度坐标转换为UTM坐标
       /// </summary>
       /// <param name="Lat">经度</param>
       /// <param name="Long">纬度</param>
       /// <param name="SRID">UTM中心线所在的区域ID</param>
       /// <returns></returns>
        public UTMPoint GeoToUtm( double Lat,double Long,int SRID)
        {

            int inSRID = 4326;
            int outSRID = SRID;
            
            //Get input coordinate system by ID from CSV dataset
            ICoordinateSystem csIn = SridReader.GetCSbyID(inSRID);
                       //Get output coordinate system by ID from CSV dataset
            ICoordinateSystem csOut = SridReader.GetCSbyID(outSRID);
            //Create coordinate transformation instance
            ICoordinateTransformation trans = null;
            trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(csIn, csOut);
                    ///Perform transformation
            double[] result = trans.MathTransform.Transform(new double[] { Lat, Long });
            UTMPoint newutm = new UTMPoint(); 
            newutm.x=result[0];
            newutm.y = result[1];
            return newutm ;

        }
        /// <summary>
        /// 将经纬度坐标转换为UTM坐标
        /// </summary>
        /// <param name="Lat">经度</param>
        /// <param name="Long">纬度</param>
        /// <param name="SRID">UTM中心线所在的区域ID</param>
        /// <returns></returns>
        public GeoPoint UtmToGeo(double Lat, double Long, int SRID)
        {

            int inSRID = SRID;
            int outSRID =4326 ;

            //Get input coordinate system by ID from CSV dataset
            ICoordinateSystem csIn = SridReader.GetCSbyID(inSRID);
            //Get output coordinate system by ID from CSV dataset
            ICoordinateSystem csOut = SridReader.GetCSbyID(outSRID);
            //Create coordinate transformation instance
            ICoordinateTransformation trans = null;
            trans = new CoordinateTransformationFactory().CreateFromCoordinateSystems(csIn, csOut);
            ///Perform transformation
            double[] result = trans.MathTransform.Transform(new double[] { Lat, Long });
            GeoPoint newGeo = new GeoPoint();
            newGeo.x = result[0];
            newGeo.y = result[1];
            return newGeo;

        }
      
    }
}
